import type { Recordable } from '@vben/types';

import type { Page } from '../base';

import { requestClient } from '#/api/request';

export namespace LimbDeviceApi {
  export interface LimbDevice {
    [key: string]: any;
    id: string;
    modelId: string;
    name: string;
    code?: string;
    type?: string;
    description?: string;
    status?: number;
    isDeleted?: boolean;
    createdAt?: string;
    updatedAt?: string;
    deletedAt?: string;
  }

  export interface DeviceUpdateInput {
    status?: number;
    isDeleted?: boolean;
    createdAt?: string;
    updatedAt?: string;
    deletedAt?: string;
    code?: string;
    type?: string;
    description?: string;
    modelId?: string;
    name?: string;
  }
}

/**
 * 获取设备列表
 */
async function getDeviceList(params: Recordable<any>) {
  return requestClient.get<Page<LimbDeviceApi.LimbDevice>>(
    '/limb/device/list',
    { params },
  );
}

/**
 * 创建设备
 * @param data 设备数据
 */
async function createDevice(data: LimbDeviceApi.DeviceUpdateInput) {
  return requestClient.post('/limb/device', data);
}

/**
 * 更新设备
 *
 * @param id 设备 ID
 * @param data 设备数据
 */
async function updateDevice(id: string, data: LimbDeviceApi.DeviceUpdateInput) {
  return requestClient.put(`/limb/device/${id}`, data);
}

/**
 * 删除设备
 * @param id 设备 ID
 */
async function deleteDevice(id: string) {
  return requestClient.delete(`/limb/device/${id}`);
}

/**
 * 生成设备配置
 * @param id 设备 ID
 */
async function generateDeviceConfig(id: string) {
  return requestClient.get<string>(`/limb/device/generate/${id}`);
}

export {
  createDevice,
  deleteDevice,
  generateDeviceConfig,
  getDeviceList,
  updateDevice,
};
